<?php

namespace app\api\controller;

use app\api\model\Article as mArticle;
use app\api\model\Page as mPage;
use app\common\controller\Api;

/**
 * 文章列表
 */
class Article extends Api
{
    protected $noNeedLogin = ['*'];

    /**
     * 文章列表
     * @return void
     */
    public function list()
    {
        $type = request()->param('type','1');
        $where['type_data'] = $type;
        $list=(new mArticle())->where($where)->order('weigh desc')->paginate(10);
        $this->success('',$list);
    }

    /**
     * 文章详情
     * @return void
     */
    public function details(){
        $id = request()->param('id');
        $where['id']=$id;
        $data['find']=(new mArticle())->where($where)->find();
        $where_last['type_data']=$data['find']['type_data'];
        $where_last['weigh']=['>',$data['find']['weigh']];
        $data['last_article']=(new mArticle())->where($where_last)->field('id,title')->find();//上一篇
        $where_next['type_data']=$data['find']['type_data'];
        $where_next['weigh']=['<',$data['find']['weigh']];
        $data['next_article']=(new mArticle())->where($where_next)->field('id,title')->find();//下一篇
        $this->success('',$data);
    }
    public function page()
    {
        $category_id = request()->param('category_id');
        $where['category_id']=$category_id;
        $data['find']=(new mPage())->where($where)->find();
        $this->success('',$data);
    }

}